import request from "@/utils/request.js";

export default {
  //查询表单
  async projectDetails(modelId, nodeId) {
    return await request.get(`form/model/items/${modelId}/${nodeId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //新增表单模型绑定业务
  async busFormModelSave(obj) {
    return await request.post(`bus/form/model/save`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //定时任务列表
  async jobList() {
    return await request.get(`schedule/job/list`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //创建定时任务
  async jobCreate(obj) {
    return await request.post(`schedule/job/create`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //定时任务开关
  async operationEnabled(obj) {
    return await request.post(`bus/grapher/operation/enabled`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //定时任务开关
  async deleteScheduleJob(jobId) {
    return await request.delete(`schedule/job/${jobId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //提交表单数据
  async bmoFromDataSend(obj) {
    return await request.post(`form/send/data`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除表单
  async deleteForm(id) {
    return await request.delete(`bus/form/model/${id}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //获取统计图表数据
  async choiceStatistics(params) {
    return await request.get(`form/choice/statistics`, {
      params,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  async formSummary(obj) {
    return await request.get(`form/summary`, {
      params: obj,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  async exportTempalteData(formDataId) {
    return await request.get(`form/export/tempalte/data/${formDataId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //表单数据更新数据 bmo/api/v1/form/data/update/body/{formDataId}
  async updateFormData(formDataId, obj) {
    return await request.post(`form/data/update/body/${formDataId}`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除表单数据 bmo/api/v1/form/data/{formDataId}
  async deleteFormData(formDataId) {
    return await request.delete(`form/data/${formDataId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  /////////////////////////////////////////////////////////////////////
  //////////业务
  /////////////////////////////////////////////////////////////////////
  //业务详情
  async getBusInfo(id) {
    return await request.get(`bus/${id}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //获取业务列表
  async busList(params) {
    return await request.get(`bus/list`, {
      params,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  async getBusPage(params) {
    return await request.get(`bus/page`, {
      params,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //新增业务
  async addBus(obj) {
    return await request.put("bus/add", obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //修改业务
  async updateBus(obj) {
    return await request.post("bus/update", obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除业务
  async deleteBus(busId) {
    return await request.delete(`bus/${busId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  /////////////////////////////////////////////////////////////////////
  //////////业务流程
  /////////////////////////////////////////////////////////////////////
  //创建流程
  async processSaveModel(obj) {
    return await request.post("bus/process/save/model", obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //删除流程列表
  async deleteXmlModel(modelId) {
    return await request.delete(`bus/process/model/${modelId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  /////////////////////////////////////////////////////////////////////
  //////////归集器
  /////////////////////////////////////////////////////////////////////
  //获取归集器列表
  async grapherList(params) {
    return await request.get(`bus/grapher/list`, {
      params,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //创建归集器
  async grapherSave(obj) {
    return await request.post(`bus/grapher/save`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //绑定业务
  async grapherBind(obj) {
    return await request.post(`bus/grapher/bind`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //已绑定业务列表
  async grapherBindList(grapherId, type) {
    return await request.get(
      `bus/grapher/bind/list/${grapherId}?busType=${type}`, {
        baseURL: process.env.VUE_APP_BMO_API,
      }
    );
  },
  //删除归集器
  async deleteGrapher(grapherId) {
    return await request.delete(`bus/grapher/${grapherId}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  /////////////////////////////////////////////////////////////////////
  //////////数据源管理
  /////////////////////////////////////////////////////////////////////
  //测试数据库连接
  async dbPoolCheckConnection(obj) {
    return await request.post(`/db/pool/check/connection`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  //数据库的列表
  async dbPoolList(params) {
    return await request.get(`/db/pool/list`, {
      params,
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //配置数据库参数
  async dbPoolSave(obj) {
    return await request.post(`/db/pool/save`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除数据库
  async deleteDbPool(id) {
    return await request.delete(`/db/pool/delete/${id}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },

  /////////////////////////////////////////////////////////////////////
  //////////数据模型
  /////////////////////////////////////////////////////////////////////
  //新增编辑数据模型
  async createEditFormTable(obj) {
    return await request.post(`/form/table`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //获取数据模型详情
  async getFormTable(tableId) {
    return await request.get(`/form/table/${tableId} `, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //获取数据模型type = dbTable有绑定数据源的 pureTable无绑定数据模型 all 全部
  async getFormTableChoiceList(type) {
    return await request.get(`/form/table/choice/list/${type}`, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除数据模型
  async deleteFormTable(tableId) {
    return await request.delete(`/form/table/${tableId} `, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //获取数据模型数据
  async getFormTableDbData(tableId, obj) {
    return await request.post(`/form/table/db/data/${tableId}`, obj, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
  //删除数据模型数据
  async deleteFormTableBody(tableId, dataId) {
    return await request.delete(
      `/form/update/table/body/${tableId}/${dataId}  `, {
        baseURL: process.env.VUE_APP_BMO_API,
      }
    );
  },
  //编辑数据模型数据
  async createEditFormTableBody(tableId, dataId, body) {
    let data = {
      tableId,
      dataId,
      body
    };
    return await request.post(`/form/update/table/body`, data, {
      baseURL: process.env.VUE_APP_BMO_API,
    });
  },
};